/*
 * Copyright (C) 2017 zhouyou(478319399@qq.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zhouyou.http.demo.slice;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.CallBack;
import com.zhouyou.http.callback.CallClazzProxy;
import com.zhouyou.http.callback.ProgressDialogCallBack;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.demo.ResourceTable;
import com.zhouyou.http.demo.api.LoginService;
import com.zhouyou.http.demo.constant.AppConstant;
import com.zhouyou.http.demo.constant.ComParamContact;
import com.zhouyou.http.demo.customapi.test5.TestApiResult5;
import com.zhouyou.http.demo.model.ApiInfo;
import com.zhouyou.http.demo.model.AuthModel;
import com.zhouyou.http.demo.model.SectionItem;
import com.zhouyou.http.demo.model.SkinTestResult;
import com.zhouyou.http.model.utils.FileUtils;
import com.zhouyou.http.model.utils.MD5;
import com.zhouyou.http.model.utils.ToastUtils;
import com.zhouyou.http.demo.view.ProgressDialog;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.ApiResult;
import com.zhouyou.http.request.CustomRequest;
import com.zhouyou.http.subsciber.BaseSubscriber;
import com.zhouyou.http.subsciber.IProgressDialog;
import com.zhouyou.http.subsciber.ProgressSubscriber;
import com.zhouyou.http.utils.HttpLog;
import com.zhouyou.http.utils.RxUtil;
import com.zhouyou.http.view.CancelableDialog;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import retrofit2.converter.gson.GsonConverterFactory;

import java.util.List;

import static com.zhouyou.http.demo.constant.AppConstant.*;

public class MainAbilitySlice extends AbilitySlice {
    private  String ressult="";
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        Observable.create((ObservableOnSubscribe<String>) e -> {
            FileUtils.getFileFromRawfile(MainAbilitySlice.this, "1.jpg");
        }).compose(RxUtil.io_main()).subscribe(s -> {
        });
        findComponentById(ResourceTable.Id_btn_login).setClickedListener(component -> {
            Intent intent12 = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName("com.zhouyou.http.demo")
                    .withAbilityName("com.zhouyou.http.demo.LoginAbility")
                    .build();
            intent12.setOperation(operation);
            startAbility(intent12);




        });
        findComponentById(ResourceTable.Id_btn_custom_api_result).setClickedListener(component -> {
            Intent intent1 = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName("com.zhouyou.http.demo")
                    .withAbilityName("com.zhouyou.http.demo.CustomApiAbility")
                    .build();
            intent1.setOperation(operation);
            startAbility(intent1);


        });
        findComponentById(ResourceTable.Id_btn_get_request).setClickedListener(component -> onGet());
        findComponentById(ResourceTable.Id_btn_post_request).setClickedListener(component -> onPost());
        findComponentById(ResourceTable.Id_btn_object_request).setClickedListener(component -> onPostObject());
        findComponentById(ResourceTable.Id_btn_post_zson).setClickedListener(component -> onPostJson());
        findComponentById(ResourceTable.Id_btn_put).setClickedListener(component -> onPut());
        findComponentById(ResourceTable.Id_btn_delete_request).setClickedListener(component -> onDelete());
        findComponentById(ResourceTable.Id_btn_call_back).setClickedListener(component -> onCallBack());
        findComponentById(ResourceTable.Id_btn_simple_call_back).setClickedListener(component -> onSimpleCallBack());
        findComponentById(ResourceTable.Id_btn_progress_dialog_call_back).setClickedListener(component -> onProgressDialogCallBack());
        findComponentById(ResourceTable.Id_btn_return_disposable).setClickedListener(component -> onSubscription());
        findComponentById(ResourceTable.Id_btn_return_observable).setClickedListener(component -> onObservable());
        findComponentById(ResourceTable.Id_btn_progress_subscriber).setClickedListener(component -> onProgressSubscriber());
        findComponentById(ResourceTable.Id_btn_upload_file).setClickedListener(component -> {
                    Intent intent1 = new Intent();
                    Operation operation = new Intent.OperationBuilder()
                            .withBundleName("com.zhouyou.http.demo")
                            .withAbilityName("com.zhouyou.http.demo.UploadAbility")
                            .build();
                    intent1.setOperation(operation);
                    startAbility(intent1);
                }
        );
        findComponentById(ResourceTable.Id_btn_download_file).setClickedListener(component -> {
            Intent intent1 = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName("com.zhouyou.http.demo")
                    .withAbilityName("com.zhouyou.http.demo.DownloadAbility")
                    .build();
            intent1.setOperation(operation);
            startAbility(intent1);
        });

        findComponentById(ResourceTable.Id_btn_sysnc).setClickedListener(component -> {
            onSync();
        });
        findComponentById(ResourceTable.Id_btn_custom_call).setClickedListener(component -> {
            onCustomCall();
        });
        findComponentById(ResourceTable.Id_btn_custom_api_call).setClickedListener(component -> {
            onCustomApiCall();
        });
        findComponentById(ResourceTable.Id_btn_cache).setClickedListener(component -> {

            Intent intent1 = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName("com.zhouyou.http.demo")
                    .withAbilityName("com.zhouyou.http.demo.CacheAbility")
                    .build();
            intent1.setOperation(operation);
            startAbility(intent1);
        });
        findComponentById(ResourceTable.Id_btn_list_result).setClickedListener(component -> {
            onListResult();
        });
        findComponentById(ResourceTable.Id_btn_scene).setClickedListener(component -> {
            Intent intent1 = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName("com.zhouyou.http.demo")
                    .withAbilityName("com.zhouyou.http.demo.SceneAbility")
                    .build();
            intent1.setOperation(operation);
            startAbility(intent1);
        });


    }

    public void onGet() {
        /**
         * 访问不通，域名与相对链接不匹配
         */
        EasyHttp.get(MAIN_GET_PATH)
                .readTimeOut(30 * 1000)//局部定义读超时 ,可以不用定义
                .writeTimeOut(30 * 1000)
                .connectTimeout(30 * 1000)
                //.headers("","")//设置头参数
                //.params("name","张三")//设置参数
                //.addInterceptor()
                //.addConverterFactory()
                //.addCookie()
                .timeStamp(true)
                .execute(new SimpleCallBack<SkinTestResult>() {
                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(SkinTestResult response) {
                        if (response != null) ToastUtils.getInstance(MainAbilitySlice.this).showToast(response.toString());
                    }
                });
               /* .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String response) {
                        if (response != null) showToast(response.toString());
                    }
                });*/
    }

    /**
     * post请求
     */
    public void onPost() {
        EasyHttp.post(MAIN_POST_PATH)
                .params("newsId", "552")
                .accessToken(true)
                .timeStamp(true)
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String response) {
                        ressult=response;
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(response);
                    }
                });
    }


    /**
     * post提交Object
     */
    public void onPostObject() {
        ApiInfo apiInfo = new ApiInfo();
        ApiInfo.ApiInfoBean apiInfoBean = apiInfo.new ApiInfoBean();
        apiInfoBean.setApiKey("12345");
        apiInfoBean.setApiName("zhou-you");
        apiInfo.setApiInfo(apiInfoBean);
        EasyHttp.post(MAIN_POST_OBJECT)
                .baseUrl(new StringBuffer(SCHEMA).append(MAIN_WUXIAOLONG).toString())
                //如果是body的方式提交object，必须要加GsonConverterFactory.create()
                //他的本质就是把object转成json给到服务器，所以必须要加Gson Converter
                //切记！切记！切记！  本例可能地址不对只做演示用
                .addConverterFactory(GsonConverterFactory.create())
                .upObject(apiInfo)//这种方式会自己把对象转成json提交给服务器
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage() + "  " + e.getCode());
                    }

                    @Override
                    public void onSuccess(String response) {
                        ressult=response;
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(response);
                    }
                });
    }

    /**
     * post提交json
     */
    public void onPostJson() {
        EasyHttp.post(API)
                .baseUrl(new StringBuffer(SCHEMA).append(PATH_X).append(PATH_DLYBG).toString())
                .upJson("{\"\":\"\",\"\":\"\",\"\":\"\",\"swry_dm\":\"127053096\",\"version\":\"1.0.0\"}")
                //这里不想解析，简单只是为了做演示 直接返回String
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String s) {
                        ressult=s;
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(s);
                    }
                });
    }


    /**
     * put请求
     */
    public void onPut() {
        EasyHttp.put(new StringBuffer(SCHEMA).append(YOUDUI).append(YOUDUI_API).toString())
                .removeParam("appId")
                .params("count", "4")
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String response) {
                        ressult=response;
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(response);
                    }
                });
    }


    /**
     * delete请求
     */
    public void onDelete() {
        //测试请用自己的URL，这里为了安全去掉了地址
        //这里采用的是delete请求提交json的方式，可以选择其他需要的方式
        EasyHttp.delete(new StringBuffer(SCHEMA).append(PATH_X).append(FRINEDS).toString())
                .upJson("{\"uid\":\"10008\",\"token\":\"5b305fbeaa331\"}\n")
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String response) {
                        ressult=response;
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(response);
                    }
                });
    }

    /**
     * 基础回调
     */
    public void onCallBack() {
        //支持CallBack<SkinTestResult>、CallBack<String>回调
        Disposable mDisposable = EasyHttp.get(BASE_CALL_PATH)
                .timeStamp(true)
                .execute(new CallBack<SkinTestResult>() {
                    @Override
                    public void onStart() {
                        ressult="开始请求";
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast("开始请求");
                    }

                    @Override
                    public void onCompleted() {
                        ressult="请求完成";
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast("请求完成");
                    }

                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast("请求失败：" + e.getMessage());
                    }

                    @Override
                    public void onSuccess(SkinTestResult response) {
                        ressult=response.toString();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast("请求成功：" + response.toString());
                    }
                });
    }

    /**
     * 简单回调
     */
    public void onSimpleCallBack() {
        //支持SimpleCallBack<SkinTestResult>、SimpleCallBack<String>回调
        EasyHttp.get(MAIN_SKIN_TEST_RESULT)
                .timeStamp(true)
                .execute(new SimpleCallBack<SkinTestResult>() {
                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(SkinTestResult response) {
                        ressult=response.toString();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(response.toString());
                    }
                });
    }

    private IProgressDialog mProgressDialog = new IProgressDialog() {
        @Override
        public CancelableDialog getDialog() {
            ProgressDialog dialog = new ProgressDialog(MainAbilitySlice.this);
            dialog.setMessage("请稍候...");
            return dialog;
        }
    };

    /**
     * 带有加载进度框的回调，支持是否可以取消对话框，取消对话框时可以自动取消网络请求，不需要再手动取消。
     */
    public void onProgressDialogCallBack() {
        EasyHttp.get(MAIN_SKIN_TEST_RESULT)
                .timeStamp(true)
                .execute(new ProgressDialogCallBack<SkinTestResult>(mProgressDialog, true, true) {
                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);//super.onError(e)必须写不能删掉或者忘记了
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(SkinTestResult response) {
                        ressult=response.toString();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(response.toString());
                    }
                });
    }

    /**
     * 请求网络接口最终获取Subscription对象，通过该对象手动取消网络请求
     * 在需要取消网络请求的地方调用,一般在onDestroy()中
     */
    public void onSubscription() {
        Disposable disposable = EasyHttp.get(MAIN_SKIN_TEST_RESULT)
                .timeStamp(true)
                .execute(new SimpleCallBack<SkinTestResult>() {

                    @Override
                    public void onError(ApiException e) {
                        ressult=e.getMessage();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(SkinTestResult response) {
                        ressult=response.toString();
                        ToastUtils.getInstance(MainAbilitySlice.this).showToast(response.toString());
                    }
                });

        //EasyHttp.cancelSubscription(disposable);

    }

    /**
     * 返回Observable对象，Observable是Rxjava，有了Observable可以与其它业务逻辑很好的结合
     * 本例不讲怎么结合简单订阅下输出结果，结合需要看具体场景
     */
    public void onObservable() {
        Observable<SkinTestResult> observable = EasyHttp.get(MAIN_SKIN_TEST_RESULT)
                .timeStamp(true)
                .execute(SkinTestResult.class);

        observable.subscribe(new BaseSubscriber<SkinTestResult>() {
            @Override
            public void onError(ApiException e) {
                ressult=e.getMessage();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
            }

            @Override
            public void onNext(SkinTestResult skinTestResult) {
                ressult=skinTestResult.toString();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(skinTestResult.toString());
            }
        });
    }

    /**
     * 带有进度框的订阅者，对话框消失，可以自动取消掉网络请求
     */
    public void onProgressSubscriber() {
        Observable<SkinTestResult> observable = EasyHttp.get(MAIN_SKIN_TEST_RESULT)
                .timeStamp(true)
                .execute(SkinTestResult.class);

        observable.subscribe(new ProgressSubscriber<SkinTestResult>(this, mProgressDialog) {
            @Override
            public void onError(ApiException e) {
                super.onError(e);
                ressult=e.getMessage();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
            }

            @Override
            public void onNext(SkinTestResult skinTestResult) {
                ressult=skinTestResult.toString();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(skinTestResult.toString());
            }
        });
    }

    /**
     * 同步请求
     */
    private EventHandler mHandler = new EventHandler(EventRunner.getMainEventRunner());

    public void onSync() {
        new Thread(() -> {
            EasyHttp.get(MAIN_SKIN_TEST_RESULT)
                    .readTimeOut(30 * 1000)//局部定义读超时
                    .writeTimeOut(30 * 1000)
                    .connectTimeout(30 * 1000)
                    .timeStamp(true)
                    .syncRequest(true)//设置同步请求
                    .execute(new SimpleCallBack<SkinTestResult>() {
                        @Override
                        public void onError(final ApiException e) {
                            mHandler.postTask(new Runnable() {
                                @Override
                                public void run() {
                                    ressult=e.getMessage();
                                    ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());

                                }
                            });
                        }

                        @Override
                        public void onSuccess(final SkinTestResult response) {
                            mHandler.postTask(new Runnable() {
                                @Override
                                public void run() {
                                    ressult=response.toString();
                                    if (response != null) ToastUtils.getInstance(MainAbilitySlice.this).showToast(response.toString());

                                }
                            });
                        }
                    });
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            HttpLog.getInstance().i("====同步请求==========");
            EasyHttp.get(MAIN_SKIN_TEST_RESULT)
                    .readTimeOut(30 * 1000)//局部定义读超时
                    .writeTimeOut(30 * 1000)
                    .connectTimeout(30 * 1000)
                    .syncRequest(true)//设置同步请求
                    .timeStamp(true)
                    .execute(new SimpleCallBack<SkinTestResult>() {
                        @Override
                        public void onError(final ApiException e) {
                            mHandler.postTask(new Runnable() {
                                @Override
                                public void run() {
                                    ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
                                }
                            });
                        }

                        @Override
                        public void onSuccess(final SkinTestResult response) {
                            mHandler.postTask(new Runnable() {
                                @Override
                                public void run() {
                                    if (response != null) ToastUtils.getInstance(MainAbilitySlice.this).showToast(response.toString());
                                }
                            });
                        }
                    });
        }).start();
    }


    /**
     * 使用EasyHttp调用自定义api  注意：如果有签名的注意路径有"/"的情况如下
     * https://www.xxx.com/v1/account/login （正确）
     * https://www.xxx.com//v1/account/login (错误 可能会导致签名失败)
     */
    public void onCustomCall() {
        final String name = "18688994275";
        final String pass = "123456";
        final CustomRequest request = EasyHttp.custom().addConverterFactory(GsonConverterFactory.create(new Gson()))
                .sign(true)
                .timeStamp(true)
                .params(ComParamContact.Login.ACCOUNT, name)
                .params(ComParamContact.Login.PASSWORD, MD5.encrypt4login(pass, AppConstant.getAppSecret()))
                .build();

        LoginService mLoginService = request.create(LoginService.class);
        Observable<ApiResult<AuthModel>> observable = request.call(mLoginService.login(MAIN_LOGIN, request.getParams().urlParamsMap));
        Disposable disposable = observable.subscribe(new Consumer<ApiResult<AuthModel>>() {
            @Override
            public void accept(@NonNull ApiResult<AuthModel> result) throws Exception {
                ressult=result.toString();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(result.toString());
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {
                ressult=throwable.getLocalizedMessage();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(throwable.getMessage());
            }
        });
        //EasyHttp.cancelSubscription(disposable);//取消订阅
    }


    public void onCustomApiCall() {
        final String name = "18688994275";
        final String pass = "123456";
        final CustomRequest request = EasyHttp.custom()
                .addConverterFactory(GsonConverterFactory.create(new Gson()))
                .sign(true)
                .timeStamp(true)
                .params(ComParamContact.Login.ACCOUNT, name)
                .params(ComParamContact.Login.PASSWORD, MD5.encrypt4login(pass, AppConstant.getAppSecret()))
                .build();

        LoginService mLoginService = request.create(LoginService.class);
        Observable<AuthModel> observable = request.apiCall(mLoginService.login(MAIN_LOGIN, request.getParams().urlParamsMap));
        Disposable disposable = observable.subscribe(new Consumer<AuthModel>() {
            @Override
            public void accept(@NonNull AuthModel authModel) throws Exception {
                ressult=authModel.toString();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(authModel.toString());
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {
                ressult=throwable.getMessage();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(throwable.getMessage());
            }
        });
    }


    public void onListResult() {
        //方式一：
       /* EasyHttp.get"http://news-at.zhihu.com/api/3/sections")
                .execute(new CallBackProxy<TestApiResult5<List<SectionItem>>, List<SectionItem>>(new SimpleCallBack<List<SectionItem>>() {
                    @Override
                    public void onError(ApiException e) {
                        showToast(e.getMessage());
                    }

                    @Override
                    public void onSuccess(List<SectionItem> sectionItems) {
                        showToast(sectionItems.toString());
                    }
                }) {
                });*/
        //方式二：
        /*Observable<List<SectionItem>> observable = EasyHttp.get("http://news-at.zhihu.com/api/3/sections")
                .execute(new CallClazzProxy<TestApiResult5<List<SectionItem>>, List<SectionItem>>(new TypeToken<List<SectionItem>>() {
                }.getType()) {
                });
        observable.subscribe(new Consumer<List<SectionItem>>() {
            @Override
            public void accept(@NonNull List<SectionItem> sectionItems) throws Exception {
                showToast(sectionItems.toString());
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {
                showToast(throwable.getMessage());
            }
        });*/
        //方式三：
        Observable<List<SectionItem>> observable = EasyHttp.get(new StringBuffer(SCHEMA).append(MAIN_NEWS).append(MAIN_API).toString())
                .execute(new CallClazzProxy<TestApiResult5<List<SectionItem>>, List<SectionItem>>(new TypeToken<List<SectionItem>>() {
                }.getType()) {
                });
        observable.subscribe(new ProgressSubscriber<List<SectionItem>>(this, mProgressDialog) {
            @Override
            public void onError(ApiException e) {
                super.onError(e);
                ressult=e.getMessage();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(e.getMessage());
            }

            @Override
            public void onNext(List<SectionItem> sectionItems) {
                ressult=sectionItems.toString();
                ToastUtils.getInstance(MainAbilitySlice.this).showToast(sectionItems.toString());
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    public String getResult() {
        return ressult;
    }
}
